package com.hengjun.baccarat.pojo;

import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;

import com.hengjun.baccarat.common.ConfigData;
import com.hengjun.baccarat.net.UrlConn;
import com.hengjun.baccarat.utils.BcSysUser;
import com.hengjun.baccarat.utils.GetJSON;
import com.hengjun.baccarat.utils.RecordCore;

public class GlobalService {

	public static List<RecordCore> list = null;

	public static boolean checkOpenType(String openType) {
		boolean flag = false;
		if (openType.equals(ConfigData.BANK_STYLE_NAME)
				|| openType.equals(ConfigData.BANK_PLAYER_DOUBLE_STYLE_NAME)
				|| openType.equals(ConfigData.BANK_PLAYER_DOUBLE_STYLE_NAME)
				|| openType.equals(ConfigData.BANK_TWO_DOUBLE_STYLE_NAME)
				|| openType.equals(ConfigData.PLAYERS_STYLE_NAME)
				|| openType.equals(ConfigData.PLAYERS_DOUBLE_STYLE_NAME)
				|| openType.equals(ConfigData.PLAYERS_BANK_DOUBLE_STYLE_NAME)
				|| openType.equals(ConfigData.PLAYERS_TOW_STYLE_NAME)
				|| openType.equals(ConfigData.TIE_STYLE_NAME)
				|| openType.equals(ConfigData.TIE_PLAYER_DOUBLE_STYLE_NAME)
				|| openType.equals(ConfigData.TIE_BANK_DOUBLE_STYLE_NAME)
				|| openType.equals(ConfigData.TIE_TOW_STYLE_NAME)) {
			flag = true;

		}
		return flag;
	}

	public static String getOpenType(String openType) {

		if (openType.equals(ConfigData.BANK_STYLE_NAME)) {

			return ConfigData.BANK_STYLE;
		}
		if (openType.equals(ConfigData.BANK_DOUBLE_STYLE_NAME)) {

			return ConfigData.BANK_DOUBLE_STYLE;
		}
		if (openType.equals(ConfigData.BANK_PLAYER_DOUBLE_STYLE_NAME)) {

			return ConfigData.BANK_PLAYER_DOUBLE_STYLE;
		}
		if (openType.equals(ConfigData.BANK_TWO_DOUBLE_STYLE_NAME)) {

			return ConfigData.BANK_TWO_DOUBLE_STYLE;
		}

		if (openType.equals(ConfigData.PLAYERS_STYLE_NAME)) {

			return ConfigData.PLAYERS_STYLE;
		}
		if (openType.equals(ConfigData.PLAYERS_DOUBLE_STYLE_NAME)) {

			return ConfigData.PLAYERS_DOUBLE_STYLE;
		}
		if (openType.equals(ConfigData.PLAYERS_BANK_DOUBLE_STYLE_NAME)) {

			return ConfigData.PLAYERS_BANK_DOUBLE_STYLE;
		}
		if (openType.equals(ConfigData.PLAYERS_TOW_STYLE_NAME)) {

			return ConfigData.PLAYERS_TWO_DOUBLE_STYLE;
		}

		if (openType.equals(ConfigData.TIE_STYLE_NAME)) {

			return ConfigData.TIE_STYLE;
		}
		if (openType.equals(ConfigData.TIE_PLAYER_DOUBLE_STYLE_NAME)) {

			return ConfigData.TIE_PLAYER_DOUBLE_STYLE;
		}
		if (openType.equals(ConfigData.TIE_BANK_DOUBLE_STYLE_NAME)) {

			return ConfigData.TIE_BANK_DOUBLE_STYLE;
		}
		if (openType.equals(ConfigData.TIE_TOW_STYLE_NAME)) {

			return ConfigData.TIE_TWO_DOUBLE_STYLE;
		}
		return "";

	}

	public String getType(String openType) {

		if (openType.equals(ConfigData.BANK_STYLE_NAME)
				|| openType.equals(ConfigData.BANK_DOUBLE_STYLE_NAME)
				|| openType.equals(ConfigData.BANK_PLAYER_DOUBLE_STYLE_NAME)
				|| openType.equals(ConfigData.BANK_TWO_DOUBLE_STYLE_NAME)) {

			return ConfigData.CLASSIFY_Z;

		}

		if (openType.equals(ConfigData.PLAYERS_STYLE_NAME)
				|| openType.equals(ConfigData.PLAYERS_DOUBLE_STYLE_NAME)
				|| openType.equals(ConfigData.PLAYERS_BANK_DOUBLE_STYLE_NAME)
				|| openType.equals(ConfigData.PLAYERS_TOW_STYLE_NAME)

		) {
			return ConfigData.CLASSIFY_X;

		}
		return "";
	}

	
	public static void addBettingResultList(String str){
		ViewDataObject view = ViewDataObject.getViewDataObject();
		List<String> list=view.getBettingResultList();
		list.add(str);
		view.setBettingResultList(list);
	}
	
	// 計算大路
	@SuppressWarnings({ "unchecked", "unused" })
	public  static void culBigStreetCellObject(String openType, double wintemp) {

		openType = getOpenType(openType);
		ViewDataObject view = ViewDataObject.getViewDataObject();
		List<Object> bigStreetArrayList = view.getBigStreetArrayList();
		CellObject2 cellObject = new CellObject2();
		cellObject.setOpenType(openType);
		;

		if (openType.equals(ConfigData.BANK_STYLE)
				|| openType.equals(ConfigData.BANK_DOUBLE_STYLE)
				|| openType.equals(ConfigData.BANK_PLAYER_DOUBLE_STYLE)
				|| openType.equals(ConfigData.BANK_TWO_DOUBLE_STYLE)

		) {
			String type = ConfigData.CLASSIFY_Z;
			cellObject.setType(type);
			cellObject.setTieContinus(0);
			cellObject.setWinTotal(wintemp);
			cellObject.setBeforeType(openType);

		}

		if (openType.equals(ConfigData.PLAYERS_STYLE)
				|| openType.equals(ConfigData.PLAYERS_DOUBLE_STYLE)
				|| openType.equals(ConfigData.PLAYERS_BANK_DOUBLE_STYLE)
				|| openType.equals(ConfigData.PLAYERS_TWO_DOUBLE_STYLE)

		) {
			String type = ConfigData.CLASSIFY_X;
			cellObject.setType(type);
			cellObject.setTieContinus(0);
			cellObject.setWinTotal(wintemp);
			cellObject.setBeforeType(openType);

		}

		if (openType.equals(ConfigData.TIE_STYLE)
				|| openType.equals(ConfigData.TIE_BANK_DOUBLE_STYLE)
				|| openType.equals(ConfigData.TIE_PLAYER_DOUBLE_STYLE)
				|| openType.equals(ConfigData.TIE_TWO_DOUBLE_STYLE)) {
			int index = 0;
			if (bigStreetArrayList.size() > 0) {
				index = bigStreetArrayList.size();
			}
			String type = "";
			cellObject.setBeforeType("");
			if (index > 0) {

				int tieContinues = cellObject.getTieContinus() + 1;

				cellObject.setTieContinus(tieContinues);
				List<CellObject2> lastTableArray = (List<CellObject2>) bigStreetArrayList
						.get(index - 1);

				for (int j = lastTableArray.size() - 1; j >= 0; j--) {

					CellObject2 celltemp = lastTableArray.get(j);
					type = celltemp.getType();

					cellObject.setBeforeType(celltemp.getBeforeType());
					cellObject.setCol(celltemp.getCol());
					cellObject.setRow(celltemp.getRow());
					cellObject.setRealityRow(celltemp.getRealityRow());
					cellObject.setRealityCol(celltemp.getRealityCol());
					cellObject.setTieContinus(celltemp.getTieContinus() + 1);
					cellObject.setWinTotal(celltemp.getWinTotal() + wintemp);
					lastTableArray.remove(j);
					break;

				}
				cellObject.setType(type);

			} else {
				int tieContinues = 1;
				cellObject.setTieContinus(tieContinues);
				cellObject.setWinTotal(wintemp);
				cellObject.setType(type);
			}

		}

		int index = 0;
		int num = bigStreetArrayList.size();
		if (num == 0) {
			List<CellObject2> firstArray = new ArrayList<CellObject2>();
			cellObject.setRow(0);
			cellObject.setCol(0);
			cellObject.setRealityCol(0);
			cellObject.setRealityRow(0);
			firstArray.add(cellObject);
			bigStreetArrayList.add(firstArray);
			view.setBigStreetArrayList(bigStreetArrayList);

			return;
		}
		if (num > 0) {
			index = bigStreetArrayList.size() - 1;
		}

		List<CellObject2> lastTableArray = (List<CellObject2>) bigStreetArrayList
				.get(index);
		for (int j = lastTableArray.size() - 1; j >= 0; j--) {

			CellObject2 celltemp2 = lastTableArray.get(j);
			if (!celltemp2.getBeforeType().equals("")
					&& celltemp2.getType().equals(cellObject.getType())
					&& !openType.equals(ConfigData.TIE_BANK_DOUBLE_STYLE)
					&& !openType.equals(ConfigData.TIE_PLAYER_DOUBLE_STYLE)
					&& !openType.equals(ConfigData.TIE_TWO_DOUBLE_STYLE)
						&& !openType.equals(ConfigData.TIE_STYLE)
					) {
				int deRow = ConfigData.DEFAULT_ROW;
				if (celltemp2.getRow() >= deRow
						&& celltemp2.getRealityCol() == 0) {
					cellObject.setRow(deRow);
					int col = celltemp2.getCol() + 1;
					cellObject.setCol(col);
					cellObject.setRealityCol(celltemp2.getRealityCol());
					cellObject.setRealityRow(celltemp2.getRealityRow() + 1);
				} else if (celltemp2.getRow() >= deRow
						&& celltemp2.getRealityCol() >= 1) {
					cellObject.setRow(deRow + 1);
					int col = celltemp2.getCol();
					cellObject.setCol(col);
					cellObject.setRealityCol(celltemp2.getRealityCol());
					cellObject.setRealityRow(celltemp2.getRealityRow() + 1);

				} else {
					cellObject.setRow(celltemp2.getRow() + 1);
					int col = celltemp2.getCol();
					cellObject.setCol(col);
					cellObject.setRealityCol(celltemp2.getRealityCol());
					cellObject.setRealityRow(celltemp2.getRealityRow() + 1);
				}
				break;
			}
			if (!celltemp2.getBeforeType().equals("")
					&& !celltemp2.getType().equals(cellObject.getType())
					&& (openType.equals(ConfigData.TIE_STYLE)
						||openType.equals(ConfigData.TIE_BANK_DOUBLE_STYLE)
						||openType.equals(ConfigData.TIE_PLAYER_DOUBLE_STYLE)
						||	openType.equals(ConfigData.TIE_TWO_DOUBLE_STYLE)
							)) {
				cellObject.setRow(celltemp2.getRow());
				cellObject.setCol(celltemp2.getCol());
				cellObject.setRealityRow(celltemp2.getRealityRow());
				cellObject.setRealityCol(celltemp2.getRealityCol());
				lastTableArray.remove(lastTableArray.size() - 1);
				break;
			}
			if (celltemp2.getBeforeType().equals("")
					&& celltemp2.getType().equals("")
					&&( celltemp2.getOpenType().equals(ConfigData.TIE_STYLE)
					|| celltemp2.getOpenType().equals(ConfigData.TIE_BANK_DOUBLE_STYLE)
					|| celltemp2.getOpenType().equals(ConfigData.TIE_PLAYER_DOUBLE_STYLE)		
					||celltemp2.getOpenType().equals(ConfigData.TIE_TWO_DOUBLE_STYLE)		
							)
					) {
				cellObject.setRow(celltemp2.getRow());
				cellObject.setCol(celltemp2.getCol());
				cellObject.setRealityRow(celltemp2.getRealityRow());
				cellObject.setRealityCol(celltemp2.getRealityCol());
				cellObject.setTieContinus(celltemp2.getTieContinus());
				lastTableArray.remove(lastTableArray.size() - 1);
				break;
			}
			
			
			if (celltemp2.getBeforeType().equals("")
					&& celltemp2.getType().equals(cellObject.getType())) {
				cellObject.setTieContinus(celltemp2.getTieContinus() + 1);
				cellObject.setRow(celltemp2.getRow());
				cellObject.setCol(celltemp2.getCol());
				cellObject.setRealityRow(celltemp2.getRealityRow());
				cellObject.setRealityCol(celltemp2.getRealityCol());
				lastTableArray.remove(j);
				break;
			}
			if (!celltemp2.getBeforeType().equals("")
					&& !celltemp2.getType().equals(cellObject.getType())
					&& !openType.equals(ConfigData.TIE_STYLE)
					&& !openType.equals(ConfigData.TIE_BANK_DOUBLE_STYLE)
					&& !openType.equals(ConfigData.TIE_PLAYER_DOUBLE_STYLE)		
					&&!openType.equals(ConfigData.TIE_TWO_DOUBLE_STYLE)	
					
					) {

				List<CellObject2> nextAyyay = new ArrayList<CellObject2>();
				int size = celltemp2.getRealityCol() + 1;
				cellObject.setRealityCol(size);
				cellObject.setRealityRow(0);
				cellObject.setRow(0);
				int col = celltemp2.getRealityCol() + 1;

				if (celltemp2.getRealityCol() > 0) {
					List<CellObject2> array = (List<CellObject2>) bigStreetArrayList
							.get(col - 1);
					for (int arr = array.size() - 1; arr >= 0; arr--) {
						CellObject2 cell = array.get(arr);
						if (cell.getRow() == 0) {
							col = cell.getCol() + 1;
							break;
						}

					}

				}
				cellObject.setCol(col);
				nextAyyay.add(cellObject);
				bigStreetArrayList.add(nextAyyay);
				view.setBigStreetArrayList(bigStreetArrayList);

				if (!openType.equals(ConfigData.TIE_STYLE)
						&& !openType.equals(ConfigData.TIE_BANK_DOUBLE_STYLE)
						&& !openType.equals(ConfigData.TIE_PLAYER_DOUBLE_STYLE)
						&& !openType.equals(ConfigData.TIE_TWO_DOUBLE_STYLE)) {
					String bigEye = culOherCellObject(1, 1, 0, 2, 1, 1, 2);
					if (!bigEye.equals("")) {
						List<Object> bigEyeList = culOtherStreetCellObject(
								bigEye, view.getBigEyeList(), wintemp);
						view.setBigEyeList(bigEyeList);
					}
					String littleEye = culOherCellObject(1, 2, 0, 3, 2, 1, 3);
					if (!littleEye.equals("")) {
						List<Object> littleEyeList = culOtherStreetCellObject(
								littleEye, view.getLittleEyeList(), wintemp);
						view.setLittleEyeList(littleEyeList);
					}

					String xiaoQiangEye = culOherCellObject(1, 3, 0, 4, 3, 1, 4);
					if (!xiaoQiangEye.equals("")) {
						List<Object> xiaoQiangEyeList = culOtherStreetCellObject(
								xiaoQiangEye, view.getXiaoQiangList(), wintemp);
						view.setXiaoQiangList(xiaoQiangEyeList);
					}

				}

				return;

			}

		}
		int realityCol = cellObject.getRealityCol();
		int cellRow = cellObject.getRow();
		int cellCol = cellObject.getCol();
		if (realityCol > 0 && (!openType.equals(ConfigData.TIE_STYLE)  && 
				!openType.equals(ConfigData.TIE_BANK_DOUBLE_STYLE) &&
				!openType.equals
				(ConfigData.TIE_PLAYER_DOUBLE_STYLE) &&
				!openType.equals(ConfigData.TIE_TWO_DOUBLE_STYLE) 
				
				)) {
			List<CellObject2> lastArray = (List<CellObject2>) bigStreetArrayList
					.get(realityCol);

			boolean falg = true;
			for (int i = bigStreetArrayList.size() - 1; i >= 0; i--) {
				List<CellObject2> tempArray = (List<CellObject2>) bigStreetArrayList
						.get(i);
				for (int j = 0; j < tempArray.size(); j++) {

					CellObject2 cell2 = tempArray.get(j);
					if (cell2.getRow().intValue() == cellRow
							&& cell2.getCol().intValue() == cellCol) {
						falg = false;
						break;
					}
				}
				if (!falg) {
					break;

				}
			}

			if (!falg) {
				boolean underFlag = true;
				for (int j = 0; j < lastArray.size(); j++) {
					CellObject2 cell2 = lastArray.get(j);
					if (cell2.getRow() == cellRow - 1
							&& cell2.getCol() == cellCol - 1) {

						cellObject.setRow(cellRow - 1);
						cellObject.setCol(cellCol + 1);
						underFlag = false;
						break;
					}
					if (underFlag) {
						cellObject.setRow(cellRow - 1);
						cellObject.setCol(cellCol + 1);
					}
				}
			}
			if (falg) {
				boolean shuipinFlag = true;
				List<CellObject2> firstarray = (List<CellObject2>) bigStreetArrayList
						.get(realityCol - 1);
				for (int i = 0; i < firstarray.size(); i++) {
					CellObject2 cell3 = firstarray.get(i);
					if (cell3.getRow().intValue() > 5) {

						cellObject.setRow(cellRow - 1);
						cellObject.setCol(cellCol + 1);
						shuipinFlag = false;
						break;
					}

				}

				if (shuipinFlag) {

					for (int j = 0; j < lastArray.size(); j++) {
						CellObject2 cell2 = lastArray.get(j);
						if (cell2.getRow() == cellRow - 1
								&& cell2.getCol() == cellCol - 1) {

							cellObject.setRow(cellRow - 1);
							cellObject.setCol(cellCol + 1);
							break;
						}
					}

				}

			}
		}

		if (cellObject.getRow().intValue() > ConfigData.DEFAULT_ROW) {
			cellObject.setRow(cellRow - 1);
			cellObject.setCol(cellCol + 1);
		}
		List<CellObject2> tempArrayy = (List<CellObject2>) bigStreetArrayList
				.get(realityCol);
		if (bigStreetArrayList.size() > realityCol) {
			bigStreetArrayList.remove(realityCol);
		}
		tempArrayy.add(cellObject);
		bigStreetArrayList.add(tempArrayy);
		view.setBigStreetArrayList(bigStreetArrayList);

		if (!openType.equals(ConfigData.TIE_STYLE)
				&& !openType.equals(ConfigData.TIE_BANK_DOUBLE_STYLE)
				&& !openType.equals(ConfigData.TIE_PLAYER_DOUBLE_STYLE)
				&& !openType.equals(ConfigData.TIE_TWO_DOUBLE_STYLE)) {
			String bigEye = culOherCellObject(1, 1, 0, 2, 1, 1, 2);
			if (!bigEye.equals("")) {
				List<Object> bigEyeList = culOtherStreetCellObject(bigEye,
						view.getBigEyeList(), wintemp);
				view.setBigEyeList(bigEyeList);
			}
			String littleEye = culOherCellObject(1, 2, 0, 3, 2, 1, 3);
			if (!littleEye.equals("")) {
				List<Object> littleEyeList = culOtherStreetCellObject(
						littleEye, view.getLittleEyeList(), wintemp);
				view.setLittleEyeList(littleEyeList);
			}

			String xiaoQiangEye = culOherCellObject(1, 3, 0, 4, 3, 1, 4);
			if (!xiaoQiangEye.equals("")) {
				List<Object> xiaoQiangEyeList = culOtherStreetCellObject(
						xiaoQiangEye, view.getXiaoQiangList(), wintemp);
				view.setXiaoQiangList(xiaoQiangEyeList);
			}

		}

	}

	@SuppressWarnings("unchecked")
	private static String culOherCellObject(int startRow, int startCol,
			int bakrow, int bakcol, int comparecol,
			int qiZhengCompareColbefore, int qiZhengCompareCol) {

		ViewDataObject view = ViewDataObject.getViewDataObject();
		List<Object> bigStreetArrayList = view.getBigStreetArrayList();
		List<CellObject2> cellList = (List<CellObject2>) (bigStreetArrayList
				.get(bigStreetArrayList.size() - 1));
		CellObject2 ce = cellList.get(cellList.size() - 1);
		String openType = "";
		boolean falg = false;
		for (int i = 0; i < bigStreetArrayList.size(); i++) {

			List<CellObject2> arraytemp = (List<CellObject2>) bigStreetArrayList
					.get(i);
			for (int j = 0; j < arraytemp.size(); j++) {
				CellObject2 cellbig = arraytemp.get(j);
				if (cellbig.getRow().intValue() == startRow
						&& cellbig.getCol().intValue() == startCol
						|| (cellbig.getRow().intValue() == bakrow && cellbig
								.getCol().intValue() == bakcol)) {
					falg = true;
					break;
				}
			}
			if (falg) {
				break;
			}
		}

		if (falg) {
			if (ce.getRow() == 0) {
				List<CellObject2> currentCellList = (List<CellObject2>) bigStreetArrayList
						.get(ce.getRealityCol() - qiZhengCompareCol);
				CellObject2 currentCell = currentCellList.get(currentCellList
						.size() - 1);

				List<CellObject2> beforeCellList = (List<CellObject2>) bigStreetArrayList
						.get(ce.getRealityCol() - qiZhengCompareColbefore);
				CellObject2 beforeCell = beforeCellList.get(beforeCellList
						.size() - 1);

				if (beforeCell.getRealityRow().intValue() == currentCell
						.getRealityRow().intValue()) {
					openType = ConfigData.BANK_STYLE;
				} else {
					openType = ConfigData.PLAYERS_STYLE;
				}
			}
			if (ce.getRealityRow() == 1) {
				List<CellObject2> currentCellList = (List<CellObject2>) bigStreetArrayList
						.get(ce.getRealityCol() - comparecol);
				CellObject2 currentCell = currentCellList.get(currentCellList
						.size() - 1);

				if (currentCell.getRealityRow() >= 1) {

					openType = ConfigData.BANK_STYLE;
				} else {
					openType = ConfigData.PLAYERS_STYLE;
				}
			}
			if (ce.getRealityRow() > 1) {

				List<CellObject2> beforeCellList = (List<CellObject2>) bigStreetArrayList
						.get(ce.getRealityCol() - comparecol);
				CellObject2 beforeCell = beforeCellList.get(beforeCellList
						.size() - 1);
				List<CellObject2> currentCellList = (List<CellObject2>) bigStreetArrayList
						.get(ce.getRealityCol());
				CellObject2 currentCell = currentCellList.get(currentCellList
						.size() - 1);

				if (currentCell.getRealityRow().intValue()
						- beforeCell.getRealityRow().intValue() >= 2
						|| beforeCell.getRealityRow().intValue() >= currentCell
								.getRealityRow()
						&& ce.getRealityRow().intValue() != 1) {

					openType = ConfigData.BANK_STYLE;

				}
				if (beforeCell.getRealityRow().intValue() >= currentCell
						.getRealityRow().intValue()
						&& ce.getRealityRow().intValue() != 1) {

					openType = ConfigData.BANK_STYLE;
				}
				if (currentCell.getRealityRow().intValue()
						- beforeCell.getRealityRow().intValue() < 2
						&& currentCell.getRealityRow().intValue()
								- beforeCell.getRealityRow().intValue() > 0) {

					openType = ConfigData.PLAYERS_STYLE;
				}
			}
			if (!openType.equals("")) {

				return openType;
			}

		}
		return openType;

	}

	@SuppressWarnings({ "unchecked", "unused" })
	public static List<Object> culOtherStreetCellObject(String openType,
			List<Object> list, double wintemp) {

		// ViewDataObject view=ViewDataObject.getViewDataObject();

		List<Object> bigStreetArrayList = list;

		CellObject2 cellObject = new CellObject2();
		cellObject.setOpenType(openType);

		if (openType.equals(ConfigData.BANK_STYLE)
				|| openType.equals(ConfigData.BANK_DOUBLE_STYLE)
				|| openType.equals(ConfigData.BANK_PLAYER_DOUBLE_STYLE)
				|| openType.equals(ConfigData.BANK_TWO_DOUBLE_STYLE)

		) {
			String type = ConfigData.CLASSIFY_Z;
			cellObject.setType(type);
			cellObject.setTieContinus(0);
			cellObject.setWinTotal(wintemp);
			cellObject.setBeforeType(openType);

		}

		if (openType.equals(ConfigData.PLAYERS_STYLE)
				|| openType.equals(ConfigData.PLAYERS_DOUBLE_STYLE)
				|| openType.equals(ConfigData.PLAYERS_BANK_DOUBLE_STYLE)
				|| openType.equals(ConfigData.PLAYERS_TWO_DOUBLE_STYLE)

		) {
			String type = ConfigData.CLASSIFY_X;
			cellObject.setType(type);
			cellObject.setTieContinus(0);
			cellObject.setWinTotal(wintemp);
			cellObject.setBeforeType(openType);

		}

		if (openType.equals(ConfigData.TIE_STYLE)
				|| openType.equals(ConfigData.TIE_BANK_DOUBLE_STYLE)
				|| openType.equals(ConfigData.TIE_PLAYER_DOUBLE_STYLE)
				|| openType.equals(ConfigData.TIE_TWO_DOUBLE_STYLE)) {
			int index = 0;
			if (bigStreetArrayList.size() > 0) {
				index = bigStreetArrayList.size();
			}
			String type = "";
			cellObject.setBeforeType("");
			if (index > 0) {

				int tieContinues = cellObject.getTieContinus() + 1;

				cellObject.setTieContinus(tieContinues);
				List<CellObject2> lastTableArray = (List<CellObject2>) bigStreetArrayList
						.get(index - 1);

				for (int j = lastTableArray.size() - 1; j >= 0; j--) {

					CellObject2 celltemp = lastTableArray.get(j);
					type = celltemp.getType();

					cellObject.setBeforeType(celltemp.getBeforeType());
					cellObject.setCol(celltemp.getCol());
					cellObject.setRow(celltemp.getRow());
					cellObject.setRealityRow(celltemp.getRealityRow());
					cellObject.setRealityCol(celltemp.getRealityCol());
					cellObject.setTieContinus(celltemp.getTieContinus() + 1);
					cellObject.setWinTotal(celltemp.getWinTotal() + wintemp);
					lastTableArray.remove(j);
					break;

				}
				cellObject.setType(type);

			} else {
				int tieContinues = 1;
				cellObject.setTieContinus(tieContinues);
				cellObject.setWinTotal(wintemp);
				cellObject.setType(type);
			}

		}

		int index = 0;
		int num = bigStreetArrayList.size();
		if (num == 0) {
			List<CellObject2> firstArray = new ArrayList<CellObject2>();
			cellObject.setRow(0);
			cellObject.setCol(0);
			cellObject.setRealityCol(0);
			cellObject.setRealityRow(0);
			firstArray.add(cellObject);
			bigStreetArrayList.add(firstArray);
			// view.setBigStreetArrayList(bigStreetArrayList);

			return bigStreetArrayList;
		}
		if (num > 0) {

			index = bigStreetArrayList.size() - 1;
		}

		List<CellObject2> lastTableArray = (List<CellObject2>) bigStreetArrayList
				.get(index);
		for (int j = lastTableArray.size() - 1; j >= 0; j--) {

			CellObject2 celltemp2 = lastTableArray.get(j);
			if (!celltemp2.getBeforeType().equals("")
					&& celltemp2.getType().equals(cellObject.getType())
					&& !openType.equals(ConfigData.TIE_STYLE)) {
				int deRow = ConfigData.DEFAULT_ROW;
				if (celltemp2.getRow() >= deRow
						&& celltemp2.getRealityCol() == 0) {
					cellObject.setRow(deRow);
					int col = celltemp2.getCol() + 1;
					cellObject.setCol(col);
					cellObject.setRealityCol(celltemp2.getRealityCol());
					cellObject.setRealityRow(celltemp2.getRealityRow() + 1);
				} else if (celltemp2.getRow() >= deRow
						&& celltemp2.getRealityCol() >= 1) {
					cellObject.setRow(deRow + 1);
					int col = celltemp2.getCol();
					cellObject.setCol(col);
					cellObject.setRealityCol(celltemp2.getRealityCol());
					cellObject.setRealityRow(celltemp2.getRealityRow() + 1);

				} else {
					cellObject.setRow(celltemp2.getRow() + 1);
					int col = celltemp2.getCol();
					cellObject.setCol(col);
					cellObject.setRealityCol(celltemp2.getRealityCol());
					cellObject.setRealityRow(celltemp2.getRealityRow() + 1);
				}
				break;
			}
			if (!celltemp2.getBeforeType().equals("")
					&& !celltemp2.getType().equals(cellObject.getType())
					&& openType.equals(ConfigData.TIE_STYLE)) {
				cellObject.setRow(celltemp2.getRow());
				cellObject.setCol(celltemp2.getCol());
				cellObject.setRealityRow(celltemp2.getRealityRow());
				cellObject.setRealityCol(celltemp2.getRealityCol());
				lastTableArray.remove(lastTableArray.size() - 1);
				break;
			}
			if (celltemp2.getBeforeType().equals("")
					&& celltemp2.getType().equals(cellObject.getType())) {
				cellObject.setTieContinus(celltemp2.getTieContinus() + 1);
				cellObject.setRow(celltemp2.getRow());
				cellObject.setCol(celltemp2.getCol());
				cellObject.setRealityRow(celltemp2.getRealityRow());
				cellObject.setRealityCol(celltemp2.getRealityCol());
				lastTableArray.remove(j);
				break;
			}
			if (!celltemp2.getBeforeType().equals("")
					&& !celltemp2.getType().equals(cellObject.getType())
					&& !openType.equals(ConfigData.TIE_STYLE)) {

				List<CellObject2> nextAyyay = new ArrayList<CellObject2>();
				int size = celltemp2.getRealityCol() + 1;
				cellObject.setRealityCol(size);
				cellObject.setRealityRow(0);
				cellObject.setRow(0);
				int col = celltemp2.getRealityCol() + 1;

				if (celltemp2.getRealityCol() > 0) {
					List<CellObject2> array = (List<CellObject2>) bigStreetArrayList
							.get(col - 1);
					for (int arr = array.size() - 1; arr >= 0; arr--) {
						CellObject2 cell = array.get(arr);
						if (cell.getRow() == 0) {
							col = cell.getCol() + 1;
							break;
						}

					}

				}
				cellObject.setCol(col);
				nextAyyay.add(cellObject);
				bigStreetArrayList.add(nextAyyay);
				// view.setBigStreetArrayList(bigStreetArrayList);

				return bigStreetArrayList;

			}

		}
		int realityCol = cellObject.getRealityCol();
		int cellRow = cellObject.getRow();
		int cellCol = cellObject.getCol();
		if (realityCol > 0 && !openType.equals(ConfigData.TIE_STYLE)) {
			List<CellObject2> lastArray = (List<CellObject2>) bigStreetArrayList
					.get(realityCol);

			boolean falg = true;
			for (int i = bigStreetArrayList.size() - 1; i >= 0; i--) {
				List<CellObject2> tempArray = (List<CellObject2>) bigStreetArrayList
						.get(i);
				for (int j = 0; j < tempArray.size(); j++) {

					CellObject2 cell2 = tempArray.get(j);
					if (cell2.getRow().intValue() == cellRow
							&& cell2.getCol().intValue() == cellCol) {
						falg = false;
						break;
					}
				}
				if (!falg) {
					break;

				}
			}

			if (!falg) {
				boolean underFlag = true;
				for (int j = 0; j < lastArray.size(); j++) {
					CellObject2 cell2 = lastArray.get(j);
					if (cell2.getRow() == cellRow - 1
							&& cell2.getCol() == cellCol - 1) {

						cellObject.setRow(cellRow - 1);
						cellObject.setCol(cellCol + 1);
						underFlag = false;
						break;
					}
					if (underFlag) {
						cellObject.setRow(cellRow - 1);
						cellObject.setCol(cellCol + 1);
					}
				}
			}
			if (falg) {
				boolean shuipinFlag = true;
				List<CellObject2> firstarray = (List<CellObject2>) bigStreetArrayList
						.get(realityCol - 1);
				for (int i = 0; i < firstarray.size(); i++) {
					CellObject2 cell3 = firstarray.get(i);
					if (cell3.getRow().intValue() > 5) {

						cellObject.setRow(cellRow - 1);
						cellObject.setCol(cellCol + 1);
						shuipinFlag = false;
						break;
					}

				}

				if (shuipinFlag) {

					for (int j = 0; j < lastArray.size(); j++) {
						CellObject2 cell2 = lastArray.get(j);
						if (cell2.getRow() == cellRow - 1
								&& cell2.getCol() == cellCol - 1) {

							cellObject.setRow(cellRow - 1);
							cellObject.setCol(cellCol + 1);
							break;
						}
					}

				}

			}
		}

		if (cellObject.getRow().intValue() > ConfigData.DEFAULT_ROW) {
			cellObject.setRow(cellRow - 1);
			cellObject.setCol(cellCol + 1);
		}
		List<CellObject2> tempArrayy = (List<CellObject2>) bigStreetArrayList
				.get(realityCol);
		if (bigStreetArrayList.size() > realityCol) {
			bigStreetArrayList.remove(realityCol);
		}
		tempArrayy.add(cellObject);
		bigStreetArrayList.add(tempArrayy);
		return bigStreetArrayList;

	}

	public synchronized static String upLoad(String recordIndex,
			String bettingResult) throws Exception {
		ViewDataObject view = ViewDataObject.getViewDataObject();
		List<Object> bigStreet = view.getBigStreetArrayList();

	
       
		String bigEyeStr=GetJSON.getListJson(view.getBigEyeList());
		String littleEyeStr= GetJSON.getListJson(view.getLittleEyeList());
		String xiaoQiangStr= GetJSON.getListJson(view.getXiaoQiangList());
		String result = UrlConn.ListUpLoad2(recordIndex, BcSysUser.getbcSysUser().getUserIndex()
				+ "", "0", GetJSON.getListJson(bigStreet), bettingResult,bigEyeStr,littleEyeStr,xiaoQiangStr);
		return result;
		

	}

	/**
	 * 默認為三位
	 * 
	 * @param dValue
	 * @return
	 */
	public static String getDoubleString(double dValue) {
		NumberFormat numberFormat = null;

		numberFormat = new DecimalFormat("0.0000");

		String strValue = numberFormat.format(dValue);
		String[] valueArray = strValue.split("\\.");
		String precialStr = valueArray[1];
		while (precialStr.endsWith("0")) {
			precialStr = precialStr.substring(0, precialStr.length() - 1);
		}
		if (precialStr.length() > 0) {
			valueArray[0] = valueArray[0] + "." + precialStr;
		}

		return valueArray[0];
	}

	public static int totalMatch() {
		ViewDataObject viewData = ViewDataObject.getViewDataObject();
		int a = 0;

		List<Object> list = viewData.getBigStreetArrayList();
		for (int i = 0; i < list.size(); i++) {
			@SuppressWarnings("unchecked")
			List<CellObject2> cellObject2List = (List<CellObject2>) list.get(i);
			for (int j = 0; j < cellObject2List.size(); j++) {
				CellObject2 cellObject2 = cellObject2List.get(j);
				if (cellObject2.getTieContinus() > 0) {
					a += cellObject2.getTieContinus() + 1;
				}
				if (cellObject2.getTieContinus() == 0) {
					a += 1;
				}
			}
		}
		return a;
	}

	public static void back() {

		ViewDataObject viewObject = ViewDataObject.getViewDataObject();
		
		List<String> bettingResultList=viewObject.getBettingResultList();
		if(bettingResultList.size()>0){
			bettingResultList.remove(bettingResultList.size()-1);
			
		}
		
		List<Object> lastBigStreetListTableArray = viewObject
				.getBigStreetArrayList();
		@SuppressWarnings("unchecked")
		List<CellObject2> bigStreetList = (List<CellObject2>) lastBigStreetListTableArray
				.get(lastBigStreetListTableArray.size() - 1);
		CellObject2 cb = bigStreetList.get(bigStreetList.size() - 1);

		boolean falg = true;
		if (cb.getTieContinus() > 0) {
			falg = false;
			cb.setTieContinus(cb.getTieContinus() - 1);
			cb.setWinTotal(cb.getWinTotal());
			bigStreetList.remove(bigStreetList.size() - 1);
			bigStreetList.add(cb);

		} else {
			bigStreetList.remove(bigStreetList.size() - 1);
		}
		lastBigStreetListTableArray
				.remove(lastBigStreetListTableArray.size() - 1);
		if (bigStreetList.size() > 0) {
			lastBigStreetListTableArray.add(bigStreetList);

		}
		viewObject.setBigStreetArrayList(lastBigStreetListTableArray);
		if (falg) {
			List<Object> lastBigEyeLisTabletArray = viewObject.getBigEyeList();

			if (lastBigEyeLisTabletArray.size() > 0) {

				@SuppressWarnings("unchecked")
				List<CellObject2> bigEyeList = (List<CellObject2>) lastBigEyeLisTabletArray
						.get(lastBigEyeLisTabletArray.size() - 1);
				bigEyeList.remove(bigEyeList.size() - 1);
				lastBigEyeLisTabletArray
						.remove(lastBigEyeLisTabletArray.size() - 1);

				if (bigEyeList.size() > 0) {
					lastBigEyeLisTabletArray.add(bigEyeList);

				}
				viewObject.setBigEyeList(lastBigEyeLisTabletArray);
			}

			List<Object> lastLittleEyeLisTabletArray = viewObject
					.getLittleEyeList();

			if (lastLittleEyeLisTabletArray.size() > 0) {

				@SuppressWarnings("unchecked")
				List<CellObject2> littleEyeList = (List<CellObject2>) lastLittleEyeLisTabletArray
						.get(lastLittleEyeLisTabletArray.size() - 1);
				littleEyeList.remove(littleEyeList.size() - 1);
				lastLittleEyeLisTabletArray.remove(lastLittleEyeLisTabletArray
						.size() - 1);

				if (littleEyeList.size() > 0) {
					lastLittleEyeLisTabletArray.add(littleEyeList);

				}
				viewObject.setLittleEyeList(lastLittleEyeLisTabletArray);
			}

			List<Object> lastXiaoQiangEyeLisTabletArray = viewObject
					.getXiaoQiangList();

			if (lastXiaoQiangEyeLisTabletArray.size() > 0) {

				@SuppressWarnings("unchecked")
				List<CellObject2> xiaoQiangList = (List<CellObject2>) lastXiaoQiangEyeLisTabletArray
						.get(lastXiaoQiangEyeLisTabletArray.size() - 1);
				xiaoQiangList.remove(xiaoQiangList.size() - 1);
				lastXiaoQiangEyeLisTabletArray
						.remove(lastXiaoQiangEyeLisTabletArray.size() - 1);

				if (xiaoQiangList.size() > 0) {
					lastXiaoQiangEyeLisTabletArray.add(xiaoQiangList);

				}
				viewObject.setXiaoQiangList(lastXiaoQiangEyeLisTabletArray);
			}

		}
	}

}